/** ********************************************************************** **\
	Fichier : serveur.hpp
	Projet  : JsVirtualWorldSrv
	Auteur  : J-S 'JSH676' Heid <js.heid@yahoo.fr>
	License : GPL
*** ********************************************************************** ***
	Copyright (C) 2009 J-S 'JSH676' Heid <js.heid@yahoo.fr>

	This file is part of JsVirtualWorldSrv.

	JsVirtualWorldSrv is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	JsVirtualWorldSrv is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with JsVirtualWorldSrv.  If not, see <http://www.gnu.org/licenses/>.
\** ********************************************************************** **/

#ifndef SERVEUR_HPP
#define SERVEUR_HPP

#include <iostream>
#include <QtNetwork>
#include <QObject>
#include <QVariant>
#include <QString>
#include <QSqlDatabase>
#include "matrix.hpp"
#include "user.hpp"

#define _LISTEN			QHostAddress::Any
#define _DEFAULT_PORT	54032
#define _INI_FILE		"./serveur.ini"
#define _PRINT_ERR(msg)	std::cerr << std::endl << "/!\\ " << msg << std::endl;
#define _PRINT(msg)		std::cout << msg << std::endl;

class Serveur : public QObject
{
Q_OBJECT

public:
	Serveur();
	void net_sendAll(const QString &message);
	void loadINI();
	void listen();
	void openDB();

	void net_parseMessage(int source, const QString &message, int sender=0);

private slots:
	void net_addConnexion();
	void net_delConnexion();
	void net_recevoir();

private:
	Matrix        m_matrice;
	QSqlDatabase *m_db;
	QTcpServer   *m_server;
	QList<User>   m_clients;

	quint16 m_tailleMessage;
	std::map<std::string, QString> m_config;
};

#endif // SERVEUR_HPP
